package com.atguigu.exam.exceptionhandlers;

import com.atguigu.exam.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result handler(Exception e) {
        e.printStackTrace();
        //输出异常日志
        log.error("服务器发生运行时异常！异常信息为：{}", e.getMessage());
        //返回异常信息
        return Result.error(e.getMessage());
    }
}
